﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp12
{
    class Player
    {
        Part p1 = new Part();
        Gz gz = new Gz();
        Random ra = new Random();
        public string Sname { get; set; }
        public Player() { }
        public Player(string sname)
        {
            Sname = sname;
        }
        public void Sw() 
        {
            Console.WriteLine("请输入你的姓名：");
            Sname = Console.ReadLine();
            p1.Sp();
            Console.WriteLine($"{Sname} vs {p1.Name} 对战");
            Console.WriteLine("开始游戏吗？<y/n>");
            string start = Console.ReadLine();
            switch (start)
            {
                case "y":
                    Wan();
                    break;
                case "n":
                    Buwan();
                    break;
                default:
                    Console.WriteLine("输入错误，请重新选择：");
                    break;
            }
        }
        public void Wan() 
        {
            int score = 0;
            int score1 = 0;
            int s = 0;
            while (true)
            {
                Console.WriteLine("请出拳：1.剪刀，2.石头，3.布（输入相应的数字）");
                int a = int.Parse(Console.ReadLine());
                gz.Cq(a);
                Console.WriteLine($"{Sname}：出拳：{gz.Chu} ");
                int c = ra.Next(1, 4);
                gz.Ca(c);
                Console.WriteLine($"{p1.Name}：出拳：{gz.Dchu}");

                if (gz.Chu == "剪刀")
                {
                    if (gz.Dchu == "剪刀")
                    {
                        Console.WriteLine("和局，真衰！嘿嘿，等着瞧吧！");
                    }
                    if (gz.Dchu == "石头")
                    {
                        Console.WriteLine($"笨蛋,{Sname}输了");
                        score1++;
                    }
                    if (gz.Dchu == "布")
                    {
                        Console.WriteLine($"恭喜，{Sname}赢了");
                        score++;
                    }
                }
                if (gz.Chu == "石头")
                {
                    if (gz.Dchu == "剪刀")
                    {
                        Console.WriteLine($"恭喜，{Sname}赢了");
                        score++;
                    }
                    if (gz.Dchu == "石头")
                    {
                        Console.WriteLine("和局，真衰！嘿嘿，等着瞧吧！");
                    }
                    if (gz.Dchu == "布")
                    {
                        Console.WriteLine($"笨蛋,{Sname}输了");
                        score1++;
                    }
                }
                if (gz.Chu == "布")
                {
                    if (gz.Dchu == "剪刀")
                    {
                        Console.WriteLine($"笨蛋,{Sname}输了");
                        score1++;
                    }
                    if (gz.Dchu == "石头")
                    {
                        Console.WriteLine($"恭喜，{Sname}赢了");
                        score++;
                    }
                    if (gz.Dchu == "布")
                    {
                        Console.WriteLine("和局，真衰！嘿嘿，等着瞧吧！");
                    }
                }
                s++;
                Console.WriteLine("是否开始下一轮？<y/n>");
                string l = Console.ReadLine();
                if (l=="y")
                {

                }
                if (l=="n")
                {
                    Console.WriteLine("====================");
                    Console.WriteLine($"{p1.Name} vs {Sname}");
                    Console.WriteLine($"对战次数 { s}");
                    Console.WriteLine();
                    Console.WriteLine("姓名    得分");
                    Console.WriteLine($"{Sname}    {score}");
                    Console.WriteLine($"{p1.Name}    {score1}");
                    if (score>score1)
                    {
                        Console.WriteLine($"我{Sname}赢了，{p1.Name}是大笨蛋");
                    }
                    if (score < score1)
                    {
                        Console.WriteLine($"我{p1.Name}赢了，{Sname}是大笨蛋");
                    }
                    if (score == score1)
                    {
                        Console.WriteLine($"晦气呀，谁都没有赢。");
                    }
                    Console.WriteLine("要开始下一局吗？<y/n>");
                    string p = Console.ReadLine();
                    if (p == "y")
                    {
                        Sw();
                    }
                    if (p == "n")
                    {
                        Buwan();
                        break;
                    }
                }
            }
        }
        public void Buwan()
        {
            Console.WriteLine("系统退出");
        }
    }
}
